<!-- /* Description for file.
 * 职能定制
 * @copyright     Copyright 2008-2010, PHInfo Services Inc. (http://www.phinfoservices.com)
 * @package       ues
 * @subpackage    ues/app/views/competencies
 * @since         ues
 * @version       V0.0.1
 * @modifiedby    张海杰2011年0623
 * @lastmodified  张海杰2011年0705
 */
 -->
<?php
echo $html->css ( 'tab' );
echo $javascript->link ( 'jquery' );
?>
<script>
//职能一层字段显示到field1 //
$(document).ready(function(){
	$("#CompetencyToplist").change(function()
	{									
		var list = $(this).find('option:selected').text();
		
		if($(this).val() < 0){
			$ ("#CompetencyField1").attr("value",'');
		}
		else{
			$("#CompetencyField1").val(list);
		}
	});
	//职能一层字段 删除 //
	$("#btnajaxDel").click(function(){
	    var op = $("#CompetencyToplist option:selected").text();
	    if(op == ""){
			alert("请选择你要删除的项");
			return;
	    }
		if(!confirm("确定删除?"))
		{
			return;
		} 			
		$.post('<?php echo ROOT_WEB_PATH; ?>/competencies/delete/'+$("#CompetencyToplist option:selected").val(),
			{
				id:$("#CompetencyToplist option:selected").val()
				},
			function(data)
			{
				window.location.reload();
				//$("#CompetencyToplist option:selected").remove();
				});
		});
	//职能一层字段 增加 //	
	$("#btnajaxAdd").click(function(){
		$("#flashMessage").hide();
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesAdd/',
			{
				data: {Competency :{name: $('#CompetencyField1').val()}}
				},
			function(data,textStatus){	
				$(data).find("aaa").each(function(){
					if($(this).attr("name")=="success"){
						//第一层职能左边下拉长内容增加
						$("#CompetencyToplist:eq(0)").append("<option></option>");
						$("#CompetencyToplist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField1').val());
						//第二层父职能右边下拉短内容增加
						$("#CompetencyDroptoplist:eq(0)").append("<option></option>");
						$("#CompetencyDroptoplist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField1').val());	
						$('#CompetencyField1').val('');
					}
					else{
					}
					//信息提示
					//$(this).attr("name");
					$('#message').attr('class',$(this).attr("name"));
					$('#message').html($(this).text());
				});	
			}
		);
	});
//职能一层字段 修改 //
	$("#btnajaxSave").click(function(){
		$("#flashMessage").hide();
		var selected = $("#CompetencyToplist option:selected").text();//选中要修改的text()值
	    if(selected == ""){
			alert("请选择你要修改的项");
			return;
	    }
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesUpdate/'+$("#CompetencyToplist option:selected").val(),
			{
				data: {Competency :{name: $('#CompetencyField1').val(),
								  id: $("#CompetencyToplist option:selected").val(),
								 fatherId:$("#CompetencyField1 option:selected").val()
								  }}
				},
			function(data,textStatus){
				$(data).find("aaa").each(function(){
					if($(this).attr("name")=="success"){
						//第一层职能左边下拉长内容修改
						$("#CompetencyToplist option:selected").remove();
						$("#CompetencyToplist:eq(0)").append("<option></option>");
						$("#CompetencyToplist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField1').val());
						//第二层父职能右边下拉短内容修改--循环
						$("#CompetencyDroptoplist option").each(function(){
							if($(this).text()==selected){
								$(this).remove();
								//alert($(this).val());
							}
						});
						$("#CompetencyDroptoplist:eq(0)").append("<option></option>");
						$("#CompetencyDroptoplist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField1').val());
						$('#CompetencyField1').val('');
					}
					else{}
						//信息提示
						//$(this).attr("name");
						$('#message').attr('class',$(this).attr("name"));
						$('#message').html($(this).text());
					});
				});
		});
});

//职能二层字段 级联菜单  同时设置职能第三层下拉菜单 //
$(function() {
	$("#CompetencyDroptoplist").change(function(){
		var CompetencyDroptoplist = $(this).val();
		if(CompetencyDroptoplist!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/competencies/getcompetencies/",{
				Competency : $(this).val()
				},function(data,textStatus){
					 $("#CompetencyQlist:eq(0)>option").remove();
					 $("#CompetencyDropqlist:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					 $("#CompetencyQlist:eq(0)").append("<option></option>");
					 $("#CompetencyQlist:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
					 $("#CompetencyDropqlist:eq(0)").append("<option></option>");
					 $("#CompetencyDropqlist:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
					 $("#CompetencyTlist").each(function(){
								$(this).empty();
						});		
				  });
			});
			
		}
	});
});
//职能二层字段显示到field2 //
$(document).ready(function(){
	$("#CompetencyQlist").change(function()
	{									
		var CompetencyQlist = $(this).find('option:selected').text();
		if($(this).val() < 0){
			$ ("#CompetencyField2").attr("value",'');
		}
		else{
			$("#CompetencyField2").val(CompetencyQlist);
		}
	});

//职能二层字段 删除 //
	$("#btnajaxDel2").click(function(){
	    var op = $("#CompetencyQlist option:selected").text();
	    if(op == ""){
			alert("请选择你要删除的项");
			return;
	    }
		if(!confirm("确定删除?"))
		{
			return;
		} 			
		$.post('<?php echo ROOT_WEB_PATH; ?>/competencies/delete/'+$("#CompetencyQlist option:selected").val(),
			{
				id:$("#CompetencyQlist option:selected").val()
				},
			function(data)
			{
				window.location.reload();
				//$("#CompetencyToplist option:selected").remove();
				});
		});
//职能二层字段 增加 //	
	$("#btnajaxAdd2").click(function(){
		$("#flashMessage").hide();
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesAdd/',
			{
				data: {Competency :{name: $('#CompetencyField2').val(),
								 fatherId: $('#CompetencyDroptoplist option:selected').val()
				}}
				},
			function(data,textStatus){
			    $(data).find("aaa").each(function(){
					if($(this).attr("name")=="success"){
						//第二层职能左边下拉长内容增加
						$("#CompetencyQlist:eq(0)").append("<option></option>");
						$("#CompetencyQlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField2').val());
						//第三层父职能右边下拉短内容增加
						$("#CompetencyDropqlist:eq(0)").append("<option></option>");
						$("#CompetencyDropqlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField2').val());		
						$('#CompetencyField2').val('');
					}
					else{}
					//信息提示
					//$(this).attr("name");
					$('#message').attr('class',$(this).attr("name"));
					$('#message').html($(this).text());
				});	
				}
			);
		});
//职能二层字段 修改 //
	$("#btnajaxSave2").click(function(){
		$("#flashMessage").hide();
		var selected = $("#CompetencyQlist option:selected").text();//选中要修改的text()值
	    if(selected == ""|| selected == "不限"){
			alert("请选择你要修改的项");
			return;
	    }
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesUpdate/'+$("#CompetencyQlist option:selected").val(),
			{
				data: {Competency :{name: $('#CompetencyField2').val(),
								  id: $("#CompetencyQlist option:selected").val(),
								  fatherId:$("#CompetencyDroptoplist option:selected").val()
				}}
				},
			function(data,textStatus){
				$(data).find("aaa").each(function(){
					if($(this).attr("name")=="success"){
						//第二层职能左边下拉长内容修改
						$("#CompetencyQlist option:selected").remove();
						$("#CompetencyQlist:eq(0)").append("<option></option>");
						$("#CompetencyQlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField2').val());
						//第三层父职能右边下拉短内容修改--循环
						$("#CompetencyDropqlist option").each(function(){
							if($(this).text()==selected){
								$(this).remove();
								//alert($(this).val());
							}
						});
						$("#CompetencyDropqlist:eq(0)").append("<option></option>");
						$("#CompetencyDropqlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField2').val());
						$('#CompetencyField2').val('');
					}
					else{
					}
					//信息提示
					//$(this).attr("name");
					$('#message').attr('class',$(this).attr("name"));
					$('#message').html($(this).text());
				});
			});
		});
});


//职能三层字段 级联菜单 //
$(function() {

	$("#CompetencyDropqlist").change(function(){
		var list = $(this).val();
		if(list!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/competencies/getcompetencies/",{
				Competency : $(this).val()
				},function(data,textStatus){
					 $("#CompetencyTlist:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					 $("#CompetencyTlist:eq(0)").append("<option></option>");
					 $("#CompetencyTlist:eq(0)>option:last").val($(this).attr("name")).html($(this).text());					 
				  });
				});
		}

	});
});

//职能三层字段显示到field3 //
$(document).ready(function(){

	$("#CompetencyTlist").change(function()
	{									
		var CompetencyQlist = $(this).find('option:selected').text();
		if($(this).val() < 0){
			$ ("#CompetencyField3").attr("value",'');
		}
		else{
			$("#CompetencyField3").val(CompetencyQlist);
		}
	});
//职能3层字段 删除 //
	$("#btnajaxDel3").click(function(){
	    var op = $("#CompetencyTlist option:selected").text();
	    if(op == ""){
			alert("请选择你要删除的项");
			return;
	    }
		if(!confirm("确定删除?"))
		{
			return;
		} 			
		$.post('<?php echo ROOT_WEB_PATH; ?>/competencies/delete/'+$("#CompetencyTlist option:selected").val(),
			{
				id:$("#CompetencyTlist option:selected").val()
				},
			function(data)
			{
				window.location.reload();
				});
		});
//职能3层字段 增加 //	
	$("#btnajaxAdd3").click(function(){
		$("#flashMessage").hide();
	    var op = $("#CompetencyDropqlist option:selected").text();
	    if(op == "" || op == "不限"){
			alert("请选择你要新增的上一级职能");
			return;
	    }
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesAdd/',
			{
				data: {Competency :{name: $('#CompetencyField3').val(),
								 fatherId: $('#CompetencyDropqlist option:selected').val()
				}}
				},
			function(data,textStatus){
					$(data).find("aaa").each(function(){
						if($(this).attr("name")=="success"){
							//第三层父职能左边下拉短长内容增加
							$("#CompetencyTlist:eq(0)").append("<option></option>");
							$("#CompetencyTlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField3').val());
							$('#CompetencyField3').val('');	
						}
						else{}
						//信息提示
						//$(this).attr("name");
						$('#message').attr('class',$(this).attr("name"));
						$('#message').html($(this).text());
					});	
					}
				);
			});
//职能3层字段 修改 //
	$("#btnajaxSave3").click(function(){
		$("#flashMessage").hide();
	    var op = $("#CompetencyTlist option:selected").text();
	    if(op == "" || op == "不限"){
			alert("请选择你要修改的项");
			return;
	    }
		$.post(
			'<?php echo ROOT_WEB_PATH; ?>/competencies/competenciesUpdate/'+$("#CompetencyTlist option:selected").val(),
			{
				data: {Competency :{name: $('#CompetencyField3').val(),
								  id: $("#CompetencyTlist option:selected").val(),
								  fatherId:$("#CompetencyDropqlist option:selected").val()
				}}
				},
			function(data,textStatus)
			{	
					$(data).find("aaa").each(function(){
						if($(this).attr("name")=="success"){
							$("#CompetencyTlist option:selected").remove();
							$("#CompetencyTlist:eq(0)").append("<option></option>");
							$("#CompetencyTlist:eq(0)>option:last").val($(this).attr("getnowid")).html($('#CompetencyField3').val());
							$('#CompetencyField3').val('');
						}
						else{}	
						//信息提示
						//$(this).attr("name");
						$('#message').attr('class',$(this).attr("name"));
						$('#message').html($(this).text());
					});
			});
	});
});

</script>
<div id="message"> </div>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Systemconfigs');//一级目录
										   echo '>';echo __('Resumesetting');//二级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('Competencies',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->

<script type="text/javascript">
$(document).ready(function() {
	
});	
</script>
<div id="container">
<?php echo $form->create('Competency',array('action'=>'init','type'=> 'post'));?>
<div id="load_1">
<div class="tabflex">
<!-- 职能一层字段  -->
<fieldset><legend><?php __('Competencies first');?></legend>
<table width="98%" cellspacing="0" cellpadding="0" border="0" style="text-align:left">
	<tr>
	<td width="50%"><?php __('field operate');?></td>
	<td width="50%"><?php __('field add');?></td>
	</tr>
	<tr>
	<td>
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
				<td>
				<!-- 职能一层字段  下拉列表 -->
				<?php
					$options = array();
					if(!empty($toplist)){
						foreach($toplist as $eachrecord)
						{
							$options[$eachrecord['Competency']['id']] = $eachrecord['Competency']['name'];
						}
					}
					echo $form->input('toplist',array('options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE2','size'=>8));		
				?>
				</td>
				<td valign="top" >

							<a><?php echo $html->image('delete.gif', array('alt' =>  __('Delete', true),'border'=>'0','id'=>'btnajaxDel'));?></a> 
							<!-- 职能一层字段删除 -->

				</td>
				<td width="50%"></td>
			</tr>
		</table>
	</td>

	<td valign="top" >
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
			<td width="50%" >
				<?php echo $form->text('Field1',array('class' => 'TextBoxE2')); ?>
			</td>		
				<td valign="top">
					<a><?php echo $html->image('add.gif', array('alt' =>  __('Add', true),'border'=>'0','id'=>'btnajaxAdd'));?> </a>
				<!-- 职能一层字段  添加 -->
				</td>
				<td valign="top">
				<a><?php echo $html->image('edit.gif', array('alt' =>  __('Edit', true),'border'=>'0','id'=>'btnajaxSave')); ?></a> 
				<!-- 职能一层字段修改 -->
				</td>
			<td width="30%"></td>

			</tr>
		</table>
	</td>
	</tr>
</table>

</fieldset>
</div>
</div>
<!-- 职能一层定制  -->

<div class="tabflex" >
<!-- 职能二层字段  -->
<fieldset><legend><?php __('Competencies second');?></legend>
<table width="98%" cellspacing="0" cellpadding="0" border="0" style="text-align:left">
	<tr>
	<td width="50%"><?php __('field operate');?></td>
	<td width="50%"><?php __('field add');?></td>
	</tr>
	<tr>
	<td>
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
				<td>
				<!-- 职能二层字段  下拉列表 -->
				<?php
					$options2 = array();
					if(!empty($list2)){
						foreach($list2 as $eachrecord)
						{
							$options2[$eachrecord['Competency']['id']] = $eachrecord['Competency']['name'];
						}
					}
				 echo $form->input('qlist',array('options'=>$options2,'label'=>false,'div'=>false,'class'=>'TextBoxE2','size'=>6));?>
				
				</td>
				<td valign="top" >

					<a><?php echo $html->image('delete.gif', array('alt' =>  __('Delete', true),'border'=>'0','id'=>'btnajaxDel2'));?></a> 
							<!-- 职能二层字段删除 -->

				</td>
				<td width="50%"></td>
			</tr>
		</table>
	</td>

	<td valign="top" >
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
			<td>
				<?php
					echo $form->input('droptoplist',array('options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE2'));		
				?>
			</td>
			</tr>
			<tr><td height="10px"></td></tr>
			<tr>
			<td width="50%">
				<?php echo $form->text('Field2',array('class' => 'TextBoxE2')); ?>
			</td>		
				<td valign="top">
					<a><?php echo $html->image('add.gif', array('alt' =>  __('Add', true),'border'=>'0','id'=>'btnajaxAdd2'));?> </a>
				<!-- 职能二层字段  添加 -->
				</td>
				<td valign="top">
				<a><?php echo $html->image('edit.gif', array('alt' =>  __('Edit', true),'border'=>'0','id'=>'btnajaxSave2')); ?></a> 
				<!-- 职能二层字段修改 -->
				</td>
			<td width="30%"></td>

			</tr>
		</table>
	</td>
	</tr>
</table>

</fieldset>
</div>
<!-- 职能二层定制  -->

<div class="tabflex">
<!-- 职能3层字段  -->
<fieldset><legend><?php __('Competencies third');?></legend>
<table width="98%" cellspacing="0" cellpadding="0" border="0" style="text-align:left">
	<tr>
	<td width="50%"><?php __('field operate');?></td>
	<td width="50%"><?php __('field add');?></td>
	</tr>
	<tr>
	<td>
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
				<td>
				<?php
					$options3 = array();
					if(!empty($list3)){
						foreach($list3 as $eachrecord)
						{
							$options3[$eachrecord['Competency']['id']] = $eachrecord['Competency']['name'];
						}
					}
				 echo $form->input('tlist',array('options'=>$options3,'label'=>false,'div'=>false,'class'=>'TextBoxE2','size'=>4));?>
				<!-- 职能3层字段  下拉列表 -->
				</td>
				<td valign="top" >

					<a><?php echo $html->image('delete.gif', array('alt' =>  __('Delete', true),'border'=>'0','id'=>'btnajaxDel3'));?></a> 
							<!-- 职能3层字段删除 -->

				</td>
				<td width="50%"></td>
			</tr>
		</table>
	</td>

	<td>
		<table width="98%" cellspacing="0" cellpadding="0" border="0" >
			<tr>
			<td>
				<?php
					$options2 = array();
					if(!empty($list2)){
						foreach($list2 as $eachrecord)
						{
							$options2[$eachrecord['Competency']['id']] = $eachrecord['Competency']['name'];
						}
					}
				 echo $form->input('dropqlist',array('options'=>$options2,'label'=>false,'div'=>false,'class'=>'TextBoxE2'));?>
				
				</td>

			</tr>
			<tr><td height="10px"></td></tr>
			<tr>
			<td width="50%">
				<?php echo $form->text('Field3',array('class' => 'TextBoxE2')); ?>
			</td>		
				<td valign="top">
					<a><?php echo $html->image('add.gif', array('alt' =>  __('Add', true),'border'=>'0','id'=>'btnajaxAdd3'));?> </a>
				<!-- 职能3层字段  添加 -->
				</td>
				<td valign="top">
				<a><?php echo $html->image('edit.gif', array('alt' =>  __('Edit', true),'border'=>'0','id'=>'btnajaxSave3')); ?></a> 
				<!-- 职能3层字段修改 -->
				</td>
			<td width="30%"></td>

			</tr>
		</table>
	</td>
	</tr>
</table>

</fieldset>
</div>
<!-- 职能3层定制  -->

</div>
<?php echo $form->end();?>

</div>
